package com.wust.weibo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.wust.http.HttpUtil;
import com.wust.util.ConstDefine;
import com.wust.util.TimeUtil;
import com.wust.weibo.WeiBoType.PageType;

/**
 * @author tianzhihen
 * @version create time：2012-7-18 下午3:15:50
 * 类说明
 */

public class WeiBoAPI {
	
	/************************************************* 主页时间线做测试  其他原封不动   **********************************************************************/
		public String getHomeMsg(PageType pageFlag, int nReqNum ) {//第一页      请求的数目  
			String url = ConstDefine.URL+"getweibo";
			Map<String,String> map=new HashMap<String, String>();
			map.put("reqnum", String.valueOf(nReqNum));
			map.put("PageType", String.valueOf(pageFlag));
		    String res;
			try {
				res = HttpUtil.postRequest(url, map);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				res=null;
				e.printStackTrace();
			}
			System.out.println("res"+res);
			return res;
//			String str="[{\"headicon\":\"http://imgsrc.baidu.com/forum/abpic/item/08e4ebfdfc039245cf2c16bb8794a4c27c1e2597.jpg\","+
//  " \"user_name\":\"天之痕\","+
//  " \"user_id\":1,"+
//"   \"mess_id\":123,"+
//  " \"mess_content\":\"早上好啊\","+
// "  \"mess_time\":\"2012-07-17\","+
//  " \"mess_img_url\":null,"+
//"	\"comment\":[{\"comment_content\":\"好你妹\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑爹的人\"},"+
//	"{\"comment_content\":\"好a\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑爹的人的爹\"}]   "+
//" },{\"headicon\":\"http://imgsrc.baidu.com/forum/abpic/item/08e4ebfdfc039245cf2c16bb8794a4c27c1e2597.jpg\","+
// "  \"user_name\":\"天之\","+
// "  \"user_id\":2,"+
// "  \"mess_id\":124,"+
// "  \"mess_content\":\"早上电风扇的啊啊\","+
//  " \"mess_time\":\"2012-07-18\","+
// "  \"mess_img_url\":null,"+
//"	\"comment\":[{\"comment_content\":\"好你妹啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人\"},"+
//"	{\"comment_content\":\"好a啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人的爹\"}]"+   
//" },{\"headicon\":\"http://imgsrc.baidu.com/forum/abpic/item/08e4ebfdfc039245cf2c16bb8794a4c27c1e2597.jpg\","+
// "  \"user_name\":\"天之\","+
// "  \"user_id\":2,"+
// "  \"mess_id\":124,"+
// "  \"mess_content\":\"早上好啊啊啊啊\","+
//  " \"mess_time\":\"2012-07-18\","+
// "  \"mess_img_url\":null,"+
//"	\"comment\":[{\"comment_content\":\"好你妹啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人\"},"+
//"	{\"comment_content\":\"好a啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人的爹\"}]"+   
//" },{\"headicon\":\"http://imgsrc.baidu.com/forum/abpic/item/08e4ebfdfc039245cf2c16bb8794a4c27c1e2597.jpg\","+
// "  \"user_name\":\"天之\","+
// "  \"user_id\":2,"+
// "  \"mess_id\":124,"+
// "  \"mess_content\":\"哈 发沙发沙发沙发 啊\","+
//  " \"mess_time\":\"2012-07-18\","+
// "  \"mess_img_url\":null,"+
//"	\"comment\":[{\"comment_content\":\"好你 撒打撒手妹啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人\"},"+
//"	{\"comment_content\":\"好a22222啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人的爹\"}]"+   
//" },{\"headicon\":\"http://imgsrc.baidu.com/forum/abpic/item/08e4ebfdfc039245cf2c16bb8794a4c27c1e2597.jpg\","+
// "  \"user_name\":\"天之\","+
// "  \"user_id\":2,"+
// "  \"mess_id\":124,"+
// "  \"mess_content\":\"早但是阿斯顿啊十大是啊啊\","+
//  " \"mess_time\":\"2012-07-18\","+
// "  \"mess_img_url\":null,"+
//"	\"comment\":[{\"comment_content\":\"好你妹啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人\"},"+
//"	{\"comment_content\":\"好a啊啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人的爹\"}]"+   
//" },{\"headicon\":\"http://imgsrc.baidu.com/forum/abpic/item/08e4ebfdfc039245cf2c16bb8794a4c27c1e2597.jpg\","+
// "  \"user_name\":\"天之\","+
// "  \"user_id\":2,"+
// "  \"mess_id\":124,"+
// "  \"mess_content\":\"早23232323啊啊\","+
//  " \"mess_time\":\"2012-07-18\","+
// "  \"mess_img_url\":null,"+
//"	\"comment\":[{\"comment_content\":\"好232323232啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人\"},"+
//"	{\"comment_content\":\"好ajfhgdhdfhdf啊啊\",\"comment_time\":\"2012-07-18\",\"user_nickname\":\"坑人的爹\"}]"+   
//" }]";
			
		}
		
		public String getWeiboDetail(int id) {
			String url = ConstDefine.URL+"getweibodetail";
			Map<String,String> map=new HashMap<String, String>();
			map.put("id", String.valueOf(id));
			String res;
			try {
				res = HttpUtil.postRequest(url, map);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				res=null;
				e.printStackTrace();
			};
		    return res;
		}
		
		public String getUserInfoByName(String name) {
			String url = ConstDefine.URL+"getUserInfo";
		
			Map<String,String> map=new HashMap<String, String>();
			map.put("user_name", name);
			String res;
			try {
				res = HttpUtil.postRequest(url, map);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				res=null;
				e.printStackTrace();
			};
		
			return res;
		}
		
		//删除一条微博
		public String delete(int id) {
			String url = ConstDefine.URL+"deleteweibo";
		
			Map<String,String> map=new HashMap<String, String>();
			map.put("id", String.valueOf(id));
			String res;
			try {
				res = HttpUtil.postRequest(url, map);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				res=null;
				e.printStackTrace();
			};
			return res;
		}
		
		public String publishMsg(String json)
		{
			//在服务器端插入成功  则  write “ok”返回
			
			
			String url=ConstDefine.URL+"insertweibo";
			Map<String,String> map=new HashMap<String, String>();
			map.put("json", json);
			String res;
			try {
				res = HttpUtil.postRequest(url, map);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				res=null;
				e.printStackTrace();
			};
			return res;
			
		
		}
		
}
